package com.web.oa.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.web.oa.mapper.BaoxiaobillMapper;
import com.web.oa.pojo.Baoxiaobill;
import com.web.oa.pojo.BaoxiaobillExample;
import com.web.oa.service.BaoXiaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BaoXiaoServiceImpl implements BaoXiaoService {
    @Autowired
    private BaoxiaobillMapper baoxiaobillMapper;

    @Override
    public PageInfo<Baoxiaobill> findLeaveBillById(Long employeeId,int pageNum) {
        PageHelper.startPage(pageNum,5);

        BaoxiaobillExample example = new BaoxiaobillExample();
        BaoxiaobillExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdEqualTo(Math.toIntExact(employeeId));
        List<Baoxiaobill> list = baoxiaobillMapper.selectByExample(example);
        return new PageInfo<>(list);
    }

    @Override
    public void saveBaoxiao(Baoxiaobill baoxiaobill) {
        Long id = baoxiaobill.getId();
        if (id==null){
            baoxiaobillMapper.insert(baoxiaobill);
        }else {
            baoxiaobillMapper.updateByPrimaryKey(baoxiaobill);
        }
    }

    @Override
    public Baoxiaobill findBaoxiaoBillById(long id) {
        return baoxiaobillMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deleteBaoxiaoByBillId(String billId) {
        baoxiaobillMapper.deleteByPrimaryKey(Long.valueOf(billId));
    }
}
